package com.dxtx.util;

import android.content.Context;
import android.telephony.TelephonyManager;

import java.util.UUID;

//获取唯一的uuid
public class UUtil {
	private static String uuid = null;

	public static String getUUID(Context context) {
		if (uuid != null) {
			return uuid;
		}
		final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		final String tmDevice, tmSerial, tmPhone, androidId;
		tmDevice = "" + tm.getDeviceId();
		tmSerial = "" + tm.getSimSerialNumber();
		androidId = ""
				+ android.provider.Settings.Secure.getString(context.getContentResolver(),
						android.provider.Settings.Secure.ANDROID_ID);
		UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
		String uniqueId = deviceUuid.toString();
		return uniqueId;
	}
	public static String getDeviceID(Context context) {
		if (uuid != null) {
			return uuid;
		}
		final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		final String tmDevice
				= "" + tm.getDeviceId();
		return tmDevice;
	}
}
